package com.fzrskj.cloud.free.user.dao;

import com.fzrskj.cloud.free.core.utils.CloudDbDrvUtils;
import com.fzrskj.cloud.free.user.bean.AlertRecordNoRepeatBean;
import ms.core.consts.SysErr;
import ms.core.db.IDbDrv;
import ms.core.object.CObject;

import java.util.Map;

public class AlertRecordNoRepeatDao extends CObject{
	//private declarations
	private IDbDrv db=null;

	//constructor function to initialize database access object
	public AlertRecordNoRepeatDao(){ db= CloudDbDrvUtils.getDbUtilsDrv(); }

	//to free resource
	@Override
	public void dispose(){
		if (db!=null) {
			db.closeConnection();
		}
		db = null;
		super.dispose();
	}

	/**
	 * 新增.
	 * @param values
	 * @return
	 */
	public int newAlertRecordNoRepeat(Map<String, Object> values){
		int ret = db.insertRecord("alert_record_norepeat",values);
		String err = db.getErrCode();
		if (!err.equals(SysErr.CODE_SUCCESS)) {
			this.log(db.getMsg());
		}

		this.setErrCode(err);
		return ret;
	}

	/**
	 * to query user_web_sub item for detail.
	 * @param keyIndex
	 * @return
	 */
	public AlertRecordNoRepeatBean queryAlertRecordNoRepeat(Integer kind, String keyIndex){
		String sql="select * from alert_record_norepeat where kind=? and keyIndex=?";
		AlertRecordNoRepeatBean ret = db.queryForBean(sql,AlertRecordNoRepeatBean.class,new Object[]{kind, keyIndex});
		String err=db.getErrCode();
		if (!err.equals(SysErr.CODE_SUCCESS)){
			this.log(db.getMsg());
		}
		this.setErrCode(err);
		return ret;
	}
}